package com.juc.countdownlatch.countdownlatch4;

import java.util.concurrent.CountDownLatch;

public class Run {

	public static void main(String[] args) {
		
		try {
			CountDownLatch comingTag = new CountDownLatch(10);
			CountDownLatch waitTag = new CountDownLatch(1);
			CountDownLatch waitRunTag = new CountDownLatch(10);
			CountDownLatch beginTag = new CountDownLatch(1);
			CountDownLatch endTag = new CountDownLatch(10);
			MyThread[] tArray  = new MyThread[10];
			for (int i = 0; i < tArray.length; i++) {
				tArray[i] = new MyThread(comingTag, waitTag, waitRunTag, beginTag, endTag);
				tArray[i].start();
			}
			System.out.println(" 裁判等待选手到来 ");
			comingTag.await();
			System.out.println(" 裁判看到所有运动员来了，各就各位 前 “巡视” 用时 5秒 ");
			Thread.sleep(5000);
			waitTag.countDown();
			System.out.println(" 各就各位 ！");
			waitRunTag.await();
			Thread.sleep(2000);
			System.out.println(" 发令枪响起 ！");
			beginTag.countDown();
			endTag.await();
			System.out.println(" 所有运动员到达 统计比赛名次 ！");
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
